/**
 * 
 */
package com.patternity.model;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Represents any design decision (pattern, stereotype, idiom...) that is listed
 * in the catalogue. Actual patterns often reference a motif that describes the
 * typical solution.
 * 
 * @author cyrillemartraire
 * 
 */
public class Pattern {

	private static final String[] IMPLIED_PATTERNS = new String[0];

	private final String name;

	private final String[] impliedPatterns;

	private final boolean moduleWise;

	private final Motif motif;

	private final Set<String> tags;

	public Pattern(final String name, final Motif motif, final String... tags) {
		this(name, IMPLIED_PATTERNS, false, motif, tags);
	}

	public Pattern(final String name, final String impliedPattern,
			final boolean moduleWise, final Motif motif, final String... tags) {
		this(name, new String[] { impliedPattern }, moduleWise, motif, tags);
	}

	public Pattern(final String name, final String[] impliedPatterns,
			final boolean moduleWise, final Motif motif, final String... tags) {
		this.name = name;
		this.impliedPatterns = impliedPatterns == null ? IMPLIED_PATTERNS
				: impliedPatterns;
		this.moduleWise = moduleWise;
		this.motif = motif == null ? new Motif() : motif;
		this.tags = new HashSet<String>();
		for (final String tag : tags) {
			this.tags.add(tag);
		}
	}

	public String getName() {
		return name;
	}

	public String[] getImpliedPatterns() {
		return impliedPatterns;
	}

	public boolean isModuleWise() {
		return moduleWise;
	}

	public Motif getMotif() {
		return motif;
	}

	public Set<String> getTags() {
		return Collections.unmodifiableSet(tags);
	}

	public boolean isStereotype() {
		return motif.getParticipants().isEmpty();
	}

}
